package cn.engage.org.controller;

import cn.engage.basic.anno.LogAnno;
import cn.engage.basic.util.AjaxResult;
import cn.engage.basic.util.PageList;
import cn.engage.org.domain.Systemdictionarydetail;
import cn.engage.org.query.SystemdictionarydetailQuery;
import cn.engage.org.service.SystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class SystemdictionarydetailController {
    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    // 查询所有
    @GetMapping
    @LogAnno(method = "findAll",methodDes = "查询字典明细")
    public List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailService.findAll();
    }

    // 查询单个
    @GetMapping("/{id}")
    @LogAnno(method = "findById",methodDes = "通过id找字典明细")
    public List<Systemdictionarydetail> findById(@PathVariable("id") Long id){
        return systemdictionarydetailService.findById(id);
    }

    // 分页查询
    @PostMapping
    @LogAnno(method = "queryByPage",methodDes = "分页查询字典明细")
    public PageList<Systemdictionarydetail> queryByPage(@RequestBody SystemdictionarydetailQuery query){
        return systemdictionarydetailService.queryByPage(query);
    }

    // 新增和修改
    @PutMapping
    @LogAnno(method = "addOrUpdate",methodDes = "新增或修改字典明细")
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        if (null == systemdictionarydetail.getId()){
            // 添加
            systemdictionarydetailService.add(systemdictionarydetail);
        }else {
            // 修改
            systemdictionarydetailService.update(systemdictionarydetail);
        }
        return AjaxResult.me().success();
    }

    // 删除
    @DeleteMapping("/{id}")
    @LogAnno(method = "delete",methodDes = "新删除字典明细")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemdictionarydetailService.delete(id);
        return AjaxResult.me().success();
    }

    // 批量删除
    @PatchMapping
    @LogAnno(method = "delete",methodDes = "批量删除字典明细")
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        systemdictionarydetailService.patchDelete(ids);
        return AjaxResult.me().success();
    }
}
